// $Id: Document.java 51 2011-10-21 16:53:27Z huijzer@gmail.com $
package lime.model;

import lime.Activator;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.model.IWorkbenchAdapter;
import org.eclipse.ui.plugin.AbstractUIPlugin;

public class Document extends RepositoryObject implements IWorkbenchAdapter {

	private boolean checkedOut;
	
	public Document(String id, String name) {
		super(id, name);
	}

	public boolean isCheckedOut() {
		return checkedOut;
	}
	
	public void setCheckedOut(boolean checkedOut) {
		this.checkedOut = checkedOut;
	}
	
	// ========================================
	// IWorkbenchAdapter
	// ========================================

	@Override
	public Object[] getChildren(Object o) {
		return new Object[] {};
	}

	@Override
	public ImageDescriptor getImageDescriptor(Object object) {
		if (isCheckedOut()) {
			return AbstractUIPlugin.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/document-access.png");
		} else {
			return AbstractUIPlugin.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/document.png");
		}
	}

	@Override
	public String getLabel(Object o) {
		return this.getObjectName();
	}

	@Override
	public Object getParent(Object o) {
		return null;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof Document) {
			Document doc = (Document) obj;
			return this.getObjectId().equals(doc.getObjectId());
		}
		return false;
	}
}
